/*
 * Copyright (c) 2021.版权所有高金磊
 */

package 领扣算法.AA中等题.统计一个数组中好对子的数目;

import java.util.HashMap;

public class Main {
    public int countNicePairs(int[] nums) {
        long nums1[]=new long[nums.length];
        for (int i = 0; i < nums.length; i++) {
            nums1[i]=nums[i];
        }
        HashMap<Long,Long> data=new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            nums1[i]-=rev(nums1[i]);
            data.put(nums1[i],data.getOrDefault(nums1[i],0L)+1);
        }
        long res=0;
        for (Long value : data.values()) {
            res+=((value*(value-1))/2);
            res%=1000000007;
        }
        return (int) (res%1000000007);
    }
    long middle;
    private long rev(long data){
        middle = 0;
        while (data!=0){
            middle*=10;
            middle+=data%10;
            data/=10;
        }
            return middle;
    }
}
